﻿
function viewImage(id) {
    layer.photos({
        photos: '#' + id
        , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
}

function closeListItem(obj) {
    var element = $(obj);
    layer.confirm('确定删除？', { icon: 3, title: '提示' }, function (index) {
        element.parent().remove();
        layer.close(index);
    });
}

function getFileJson(obj) {
    var fileArr = [];
    var fileDivArr = $(obj).children();
    $.each(fileDivArr, function (i, item) {
        var fileOjb = $(item).find('.fileItem').eq(0);
        var annexpath = $(fileOjb).attr('data-annexpath');
        var annexname = $(fileOjb).attr('data-annexname');
        var annexsize = $(fileOjb).attr('data-annexsize');
        var recordtype = $(fileOjb).attr('data-recordtype');
        fileArr.push({
            "AnnexPath": annexpath,
            "AnnexName": annexname,
            "AnnexSize": annexsize,
            "RecordType": recordtype
        });
    });
    return JSON.stringify(fileArr);
}

/**
 * 显示文件
 * @param {any} fileJson 文件Json数组
 * @param {any} id 文件Div id
 * @param {any} showType 1图片 2文件
 * @param {any} isView 是否查看模式
 */
function showFileItem(fileJson, id, showType, isView = false) {
    var fileListHtml = '';
    $.each(fileJson, function (i, item) {
        var divHtml = '';
        if (showType == 1) {
            divHtml = '<div>';
            divHtml += '<img class="fileItem" src="' + item.AnnexPath + '" data-annexpath="' + item.AnnexPath + '" data-annexname="' + item.AnnexName
                + '" data-annexsize="' + item.AnnexSize + '" data-recordtype="' + item.RecordType
                + '" alt="' + item.AnnexName + '" onclick="viewImage(\'' + id + '\')" />';
            if (!isView) {
                divHtml += '<a class="file-close" onclick="closeListItem(this)">X</a>';
            }
            divHtml += '</div>';
        } else {
            divHtml = '<div>';
            divHtml += '<a class="fileItem" target="_blank" href="' + item.AnnexPath + '" data-annexpath="' + item.AnnexPath + '" data-annexname="' + item.AnnexName
                + '" data-annexsize="' + item.AnnexSize + '" data-recordtype="' + item.RecordType + '">' + item.AnnexName + '</a>';
            if (!isView) {
                divHtml += '<a class="file-close" onclick="closeListItem(this)">X</a>';
            }
            divHtml += '</div>';
        }
        fileListHtml += divHtml;
    });
    $('#' + id).html(fileListHtml);
}
